﻿using EasyXaf.EntityDesigner.BusinessObjects;
using EasyXaf.EntityDesigner.BusinessObjects.Entities.EntityProperties;
using EasyXaf.EntityDesigner.BusinessObjects.Entities.ValidationRules;

namespace EasyXaf.EntityDesigner.Commands.PropertyTypeBuilders;

public class FileTypeBuilder : IPropertyTypeBuilder
{
    public string[] TypeAliasNames => ["file", "file!", "file?"];

    public void Build(EntityProperty property, string typeName, string[] typeParams)
    {
        property.PropertyType = PropertyType.File;

        if (typeName.EndsWith('!'))
        {
            property.IsNullable = DefaultBoolean.False;
            property.Entity.ValidationRules.Add(new RequiredRule(property.Session)
            {
                TargetProperty = property,
            });
        }
    }
}
